import Vue from 'vue'
import Router from 'vue-router'
//登录注册
import LoginRegister from "@/components/index/LoginRegister.vue";
// 首页导航加上分类类名和查询
import IndexInfo from "@/components/IndexInfo.vue";
// 轮播图和商品展示
import GoodsSlideshow from "@/components/index/GoodsSlideshow.vue";
//导航分类和搜索商品的导航栏
import GoodsCategory from "@/components/index/GoodsCategory.vue";
import VueRouter from "vue-router";
import GoodsDetail from "@/components/index/GoodsDetail.vue";

Vue.use(Router)

export default new Router({
    mode: 'history',
    routes:[
        {
            //刚访问就进入主页伦比图商品类别商品
            path: "/",
            redirect: '/index/goodsSlideshow'
        },
        {
            path:"/loginRegister",
            name:"LoginRegister",
            component:LoginRegister
        },
        {
            path:"/index",
            name:"IndexInfo",
            component:IndexInfo,
            children:[
                {
                    path:"/index/goodsSlideshow",
                    name:"GoodsSlideshow",
                    component:GoodsSlideshow,
                },
                {
                    //分类查询路由
                    path:"/index/goodsCategory/:id",
                    name:"GoodsCategory",
                    component:GoodsCategory,
                },
                {
                    //搜索查询路由
                    path: '/product-list',
                    name: 'GoodsCategory',
                    component:GoodsCategory,
                },
                {
                    //搜索查询路由
                    path: '/index/goodsDetail/:id',
                    name: 'GoodsDetail',
                    component:GoodsDetail,
                },
            ]
        }
    ]
})
// 重写 router 的 push 方法
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => {
        if (err.name === 'NavigationDuplicated') {
            // 捕获 NavigationDuplicated 错误并忽略它
            return err;
        }
        throw err;
    });
};
